<template>
    <div class="search">
        <van-search v-model="value" placeholder="请输入搜索关键词" autofocus />
        <list-vue :goods="arr"></list-vue>
    </div>
</template>

<script>
import {reqSearch} from "../../http/api"
export default {
    data() {
        return {
            //1.初始化
            value:"",
            arr:[],
        }
    },
    watch: {
        //2.监听，value变了发请求
        value(){
            if(this.value == ""){
                this.arr = []
                return
            }
            //发请求
            reqSearch({
                keywords:this.value,
            }).then((res)=>{
                // console.log(res);
                this.arr = res.data.list?res.data.list:[]
            })
        }
    }
}
</script>

<style scoped lang="less">
@import url(../../less/index.less);
</style>